Skip to content

feat(research): add Phase 11 BREADTH lower-tail correlation gate - #818

Merged
Pigbibi merged 2 commits into
mainfrom
feat/breadth-tail-correlation-gate
Nov 27, 2026
Merged

Pigbibi merged 2 commits into
mainfrom
feat/breadth-tail-correlation-gate

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

AI assistance

Antigravity AI assistant (gemini-3.1-pro)

What changed

  • Add src/quant_platform_kit/research_stats/tail_correlation.py implementing TailCorrelationResult and lower_tail_correlation_gate(...) for Phase 11 BREADTH offline cross-asset evaluation:
    • Computes lower-tail conditional Pearson correlation on benchmark drawdown sessions (benchmark_returns <= quantile(tail_quantile)) and a paired one-sided stationary-bootstrap upper confidence bound (_stationary_indices with mandatory deterministic seed).
    • Fails closed (STATUS_UNCOMPUTABLE, passes_gate=False) on invalid inputs, insufficient tail observations, zero tail variance, or undefined resample variance, and passes only when both point estimate and UCB are strictly below max_tail_correlation (default 0.50).
    • Preserves lazy numpy import via bootstrap._numpy() and strict research-only isolation (no broker/account/runtime imports).
  • Export TailCorrelationResult and lower_tail_correlation_gate from quant_platform_kit.research_stats.
  • Add comprehensive unit tests in tests/test_research_stats_tail_correlation.py.

How verified

  • git diff --check passed.
  • .venv/bin/python -m pytest -q tests/test_research_stats_tail_correlation.py tests/test_research_stats_bootstrap.py tests/test_research_stats_import_boundary.py tests/test_architecture_boundaries.py -> 40 passed in 18.13s.
  • .venv/bin/ruff check src/quant_platform_kit/research_stats/__init__.py src/quant_platform_kit/research_stats/tail_correlation.py tests/test_research_stats_tail_correlation.py -> All checks passed!.

Why

Implements the reproducible offline < 0.50 lower-tail correlation + 95% one-sided stationary-bootstrap UCB gate specified in Phase 11 BREADTH pre-registration (QuantRuntimeSettings docs/quant/breadth-preregistration.md) without touching any runtime, execution, or frozen deployment paths.

Risk

  • Tier: standard research-only statistics (src/quant_platform_kit/research_stats/ + tests/).
  • Impact: Pure offline research helper; no account reads, broker calls, orders, live/paper eligibility, or deployed service changes.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-27T18:41:48.100597Z 3540cce Manual request
🔒 Security Review ✅ Completed 2026-11-27T18:42:44.840960Z 3540cce Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@qsl-ai-reviewer

Copy link
Copy Markdown

AI Code Review (deepseek / deepseek-chat)

The new tail-correlation gate is well-structured, fails closed on invalid inputs, and has solid unit coverage. However, there is a correctness concern in the bootstrap resampling: the stationary bootstrap resamples the full series and re-derives the tail threshold per resample, which is a defensible design, but the point estimate uses the original-sample threshold while the bootstrap uses per-resample thresholds — this is a subtle inconsistency worth flagging. More importantly, the bootstrap resamples the entire series (including non-tail observations) and then conditions on the resampled tail, which can produce tail sets that are not representative of the original tail conditioning; this is a methodological choice but should be documented. No security or architecture-boundary violations found; imports are research-only and numpy is lazy. Tests cover determinism, pass/fail, invalid inputs, and to_dict. Minor: _failed does not set reason_code default in the success path (fine), and the min_tail_observations default of 10 is not validated against n.

Reviewed commit: 1f53d2a8c2 · Coverage: complete · Unresolved findings: false

Findings

  • [MEDIUM] src/quant_platform_kit/research_stats/tail_correlation.py: Bootstrap inconsistency: the point estimate conditions on the original-sample tail threshold (bench_arr <= quantile(bench_arr, tail_q)), but each bootstrap resample re-derives its own threshold (np.quantile(bench_paths, tail_q, axis=1)). This means the bootstrap distribution is not resampling the same conditioning event as the point estimate, which can bias the UCB and make the gate's statistical interpretation ambiguous. Consider either (a) fixing the threshold to the original-sample value across resamples, or (b) documenting explicitly that the bootstrap re-estimates the tail threshold per resample and why that is the intended estimand.
  • [LOW] src/quant_platform_kit/research_stats/tail_correlation.py: min_tail_observations is validated as a positive int >= 2 but is not checked against n; a caller passing min_tail_observations > n will always get insufficient_tail_observations rather than an invalid_input error, which is a slightly confusing failure mode. Consider validating min_tail_observations <= n up front.
  • [LOW] tests/test_research_stats_tail_correlation.py: No test exercises the undefined_resample_correlation failure path (e.g., a resample where the tail subset has zero variance). Adding a targeted test would lock in the fail-closed behavior for that branch.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1f53d2a8c2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Pigbibi

Pigbibi commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@qsl-ai-reviewer

Copy link
Copy Markdown

AI Code Review (deepseek / deepseek-chat)

The new tail-correlation gate is well-structured, fails closed on invalid inputs, and has solid test coverage. One medium-severity correctness issue: the bootstrap resamples the full series and recomputes the tail threshold per resample, which is a defensible design but the point estimate uses the original-sample threshold while the UCB uses per-resample thresholds — this is consistent with a stationary bootstrap of the whole process, so not a bug. However, the _failed helper drops tail_observations/tail_quantile context on the invalid_input path (acceptable) but more importantly the block > n check happens after n < min_tail_obs, and min_tail_observations is validated with minimum=2 while the docstring/PR claims fail-closed on insufficient tail observations — consistent. The real concern: _pearson_corr and the bootstrap both silently return None/fail on zero variance, which is correct fail-closed behavior. No security or architecture boundary violations detected; imports are research-only and numpy is lazy. Tests cover determinism, pass/fail, UCB-only failure, invalid inputs, and to_dict. Minor: the borderline test relies on a hand-tuned generator whose UCB>0.50 behavior is asserted only indirectly via midpoint comparison, which is robust. No high-severity findings.

Reviewed commit: 3540cce6ba · Coverage: complete · Unresolved findings: false

Findings

  • [LOW] src/quant_platform_kit/research_stats/tail_correlation.py: The invalid_input failure path returns _failed("invalid_input") without echoing back any of the parsed parameters (tail_quantile, confidence, etc.), so callers cannot distinguish which parameter was rejected. Consider including the offending field name in reason_code (e.g. invalid_input:tail_quantile) for debuggability, consistent with fail-closed diagnostics.
  • [LOW] src/quant_platform_kit/research_stats/tail_correlation.py: _pearson_corr clamps to [-1, 1] and returns None on non-finite/zero denom, but the bootstrap path uses a separate inline computation with np.clip. The two correlation implementations could drift; consider factoring a shared vectorized helper or documenting why the scalar and vectorized paths differ.
  • [LOW] tests/test_research_stats_tail_correlation.py: The borderline generator's comment claims '~0.35-0.45' tail correlation and '95% UCB > 0.50', but the test only asserts estimate < ucb and derives a midpoint threshold rather than asserting the UCB actually exceeds 0.50. The test is robust to generator drift but does not directly verify the documented borderline scenario; consider adding an explicit assertion on the UCB magnitude for the default 0.50 threshold.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 3540cce6ba

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 3540cce6ba

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@Pigbibi
Pigbibi merged commit 79ed5ca into main Nov 27, 2026
12 of 13 checks passed
@Pigbibi
Pigbibi deleted the feat/breadth-tail-correlation-gate branch November 27, 2026 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant